Path: blob/master/Part 2 - Regression/Simple Linear Regression/[R] Simple Linear Regression.ipynb
1009 views
Kernel: R
In [1]:
In [2]:
Out[2]:
b0 is constant representing the base salary of anyone who come to profession and have no experience i.e. Experience = 0
b1 is coefficient representing the slope. The more experience the more raise will be their in salary.
Here in the graph, the black line is Best Fitting Line
In [5]:
Out[5]:
Actual value vs Model value and Ordinary Least Square
In [4]:
Out[4]:
Data Preprocessing
In [22]:
In [23]:
Out[23]:
In [24]:
Out[24]:
Fitting Simple Linear Regression to the Training Set
In [25]:
In [26]:
Out[26]:
Call:
lm(formula = Salary ~ YearsExperience, data = training_set)
Residuals:
Min 1Q Median 3Q Max
-7853.2 -3691.2 904.8 3191.0 8080.8
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 27232.5 2474.3 11.01 6.17e-10 ***
YearsExperience 9103.7 392.9 23.17 6.38e-16 ***
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 5471 on 20 degrees of freedom
Multiple R-squared: 0.9641, Adjusted R-squared: 0.9623
F-statistic: 537 on 1 and 20 DF, p-value: 6.382e-16
The smaller the p-value the more significant is the Independent variable on the formula of dependent variable.
Watch this video for more information on p-value
Predicting the Test set result
In [27]:
In [28]:
Out[28]:
Visualising the Training set results
X = Years of Experience
Y = Salary
In [29]:
In [35]:
Out[35]:
MIME type unknown not supported
Visualising the Test set results
In [34]:
Out[34]:
MIME type unknown not supported